#ifndef TASK_H
#define TASK_H

#include <pthread.h>

#include "msg.h"
#include "mem.h"
#include "db_ops.h"
#include "db_info.h"

#define TASK_NAME_MAX_LEN 128

struct task_manager;
struct core_conf;
struct msg;

struct task {
	struct task *next;
	unsigned char is_default;
	char task_name[TASK_NAME_MAX_LEN];
	struct task_manager *task_manager;
	pthread_t tid;

	struct msg_queue *msg_queue_request;
	struct msg_queue *msg_queue_result;
	int (*msg_ops)(struct msg *);

	struct mm_struct *mm;

	struct db_ops *db_ops;
	struct db_data *db_data;

	void *(*func)(void *);
};

extern int register_plugin_task(struct task_manager *task_manager, char *task_name, void *(*func)(void *), int (*msg_ops)(struct msg *));
extern int register_default_task(struct task_manager *task_manager, char *task_name, void *(*func)(void *), int (*msg_ops)(struct msg *));
extern void start_default_task(struct core_conf *core_conf);
extern struct task *get_task_by_name(char *name);
extern struct task *get_task_by_tid(pthread_t tid);

#endif
